Incremental maintenance of inverted indexes for approximate string matching

ABSTRACT

In embodiments of the disclosed technology, indexes, such as inverted indexes, are updated only as necessary to guarantee answer precision within predefined thresholds which are determined with little cost in comparison to the updates of the indexes themselves. With the present technology, a batch of daily updates can be processed in a matter of minutes, rather than a few hours for rebuilding an index, and a query may be answered with assurances that the results are accurate or within a threshold of accuracy.

BACKGROUND

Approximate string matching is a problem that has received a lot ofattention recently. Existing work on information retrieval hasconcentrated on a variety of similarity measures specifically tailoredfor document retrieval purposes. Such similarity measures include TF/IDF(term frequency/inverse document frequency), a statistical measure usedin information retrieval and text mining for evaluating how important aword is to a document in a collection or corpus; BM25 (also known as“Okapi BM25”), a ranking function used by search engines to rankmatching documents according to their relevance to a given search querydeveloped in the 1970s and 1980s by Stephen E. Robertson, Karen SpärckJones, and others; and HMM (hidden Markov model) which is a statisticalmodel in which the system being modeled is assumed to be a Markovprocess with unknown parameters, and hidden parameters are determinedfrom the observable parameters.

As new implementations of retrieving short strings are becoming popular(e.g., local search engines like YellowPages.com. Yahoo!Local, andGoogle Maps), new indexing methods are needed, tailored for shortstrings. For that purpose, a number of indexing techniques and relatedalgorithms have been proposed based on length normalized similaritymeasures. A common denominator of indexes for length normalized measuresis that maintaining the underlying structures in the presence ofincremental updates is inefficient, mainly due to data dependent,precomputed weights associated with each distinct token or string.Incorporating updates, in the prior art, is usually accomplished byrebuilding the indexes at regular time intervals.

The prior art is mainly concerned with document retrieval speeds,however, given that queries often contain spelling mistakes and othererrors, and stored data have inconsistencies as well, effectivelydealing with short strings requires the use of specialized approximatestring matching indexes and algorithms. Although fundamentally documentsare long strings, the prior art, in general, makes assumptions which arenot true when dealing with shorter strings. For example, the frequencyof a term in a document might suggest that the document is related to aparticular query or topic with high probability, while the frequency ofa given token or word in a string does not imply that a longer string(containing more tokens) is more similar to the query than a shorterstring. Or the fact that shorter documents are preferred over longerdocuments (the scores of short documents are boosted according to theparsimony rule from information theory) conflicts with the fact that inpractice for short queries the vast majority of the time users expectalmost exact answers (answers of length similar to the length of thequery). This is compounded by the fact that for short strings lengthdoes not vary as much as for documents in the first place, making somelength normalization strategies ineffective. Moreover, certain otherproperties of short strings enable us to design very fast specializedapproximate string matching indexes in practice.

In many applications it is not uncommon to have to execute multipletypes of searches in parallel in order to retrieve the best candidateresults to a particular query, and use a final ranking step to combinethe results. For example, types of searches include: almost exact searchversus sub-string search, ignore special characters search, full stringsearch or per word search, n-gram (where ‘n’ is the length of componentstrings in which the data is broken into for indexing and may be, forexample, 2-grams, 3-grams, 4-grams etc.), and edit distance versusTF/IDF search.

Recently, M. Hadjieleftheriou, A. Chandel, N. Koudas, and D. Srivastavain IEEE (Institute of Electrical and Electornics Engineers)International Conference of Data Engineering (ICDE), “Fast indexes andalgorithms for set similarity selection queries”, designed specializedindex structures using L₂ length normalization that enable retrieval ofalmost exact matches with little computational cost by using veryaggressive pruning strategies. Nevertheless, the drawback of thisapproach is that the indexes are computationally expensive to constructand they do not support incremental updates. Generally speaking, eventhough various types of length normalization strategies have beenproposed in the past, approaches that have strict properties that canenable aggressive index pruning are hard to maintain incrementally,while simpler normalization methods are easier to maintain but suffer interms of query efficiency and result quality, yielding slower answersand significantly larger (i.e., fuzzier) candidate sets.

A key issue to deal with in a real system is that data is continuouslyupdated. A small number of updates to the dataset would necessitate nearcomplete recomputation of a normalized index, since such indexes aresensitive to the total number of records in the dataset, and thedistribution of terms (n-grams, words, etc.) within the strings. Giventhat datasets tend to contain tens of millions of strings and thatstrings could be updated on an hourly basis, recomputation of theindexes can be prohibitively expensive. In most practical cases, updatesare buffered and the indexes are rebuild on a weekly basis. Indexrecomputation typically takes up to a few hours to complete. However,the online nature of some applications necessitates reflecting updatesto the data as soon as possible. Hence, being able to supportincremental updates as well as very efficient query evaluation arecritical requirements.

In N. Koudas, A. Marathe, and D. Srivastava., “Propagating updates inSPIDER” (which may be found on pages 1146-1153, 2007 ICDE), twotechniques were proposed for enabling propagation of updates to theinverted indexes. The first was blocking the updates and processing themin batch. The second was thresholding updates and performing propagationin multiple stages down the index, depending on the update cost one iswilling to tolerate. That work presented heuristics that perform well inpractice, based on various observations about the distribution of tokensin real data, but it did not provide any theoretical guarantees withrespect to answer accuracy while updates have not been propagated fully.

Thus, there remains a key problem of inefficiency, regarding lengthnormalized index structures for approximate string matching, in largepart, due to data dependent, normalized weights associated with eachdistinct token or string in the database.

SUMMARY

Embodiments of the disclosed technology comprise a method and device forlimiting updates of indexes, such as inverted indexes, in a database. Itis an object of the invention to allow for efficient, partial updatingof indexes that immediately reflects the new data in the indexes in away that gives strict guarantees on the quality of subsequent queryanswers. More specifically, a technique of the disclosed technologyguarantees against false negatives and limits the number of falsepositives produced in a query, while the indexes have not been updatedfully.

In the disclosed technology, indexes, such as inverted indexes, areupdated only as necessary to guarantee answer precision withinpredefined thresholds which are determined with little cost incomparison to the updates of the indexes themselves. With the presenttechnology, a batch of daily updates can be completed (or applied) in amatter of minutes, rather than a few hours for rebuilding an index, anda query may be answered with assurances that the results are accurate orwithin a threshold of accuracy.

The inverse document frequency (IDF) for each n-gram in a plurality ofstrings is determined (as shown below), a length of each string in theplurality of strings is determined (as shown below). An inverted listfor each n-gram is created, being composed of all instances of stringsfrom a plurality of strings, that contain the particular n-gram. Eachinverted list is sorted by the length of the strings in the list. Then,an update of at least one string in the plurality of strings isreceived, such as an addition, modification or deletion to the data by auser or as a result of user input. The IDF of each n-gram isrecalculated, and as a result the length of each string changes, but theinverted lists are updated only when a predefined error threshold hasbeen reached (error being the direct result of using stale invertedlists that contain string lengths that have been computed using stalen-gram IDFs). A data query, such as a request to receive informationfrom the database, is answered based on the partially updated invertedlists.

The error threshold in n-gram IDFs, and consequently, in string lengthsis such that the similarity score computed using the outdated IDFsbetween any pair of strings, cannot diverge by more than a predeterminedfactor from the exact similarity score, computed using the exact n-gramIDFs.

SUMMARY OF THE DRAWINGS

FIG. 1 shows a flow chart of the inverted list creation and updatingprocesses.

FIG. 2 shows an example of inverted lists corresponding to data stringsfrom a table of a database in embodiments of the invention.

FIG. 3 shows a sample dataset from a database which may be used to carryout embodiments of the invention.

FIG. 4 shows a high-level block diagram of a computer that may be usedto carry out the invention.

DETAILED DESCRIPTION

Indexes for approximate string matching are mostly based on tokendecomposition of strings (e.g., into n-grams or words) and buildinginverted lists over these tokens. Then, similarity of strings ismeasured in terms of similarity of the respective token sets (e.g., byusing the vector space model to compute cosine similarity). Considerstrings “Walmart” and “Wal-mart”. We can decompose the two strings in3-gram sets {‘War’, ‘alm’, ‘lma’, ‘mar’, ‘art’} and {‘Wal’, ‘al-’,‘l-m’, ‘-ma’, ‘mar’, ‘art’}. The two sets have three 3-grams in common.Using the two sets we can compute the TF/IDF based cosine similarityscore between the two strings. In relational database tables data can beconsidered as short strings—categorical, numerical, varchar, and otherdata types that, in practice, are first converted into strings forsimilarity evaluation purposes.

The larger the intersection of two multi-sets, the larger the potentialsimilarity. Nevertheless, not all tokens are created equal. Tokens thatappear very frequently in the database (like ‘art’) carry smallinformation content, whereas rare tokens (like ‘l-m’) are more importantsemantically. Hence, the more important a token is, the larger the roleit should play in overall similarity. For that reason, weightedsimilarity measures use the Inverse Document Frequency (herein, “IDF”)to determine the weight of a token or string. The IDF of a token orstring is the inverse of the total number of times that this token orstring appears in a data collection, such as a database.

FIG. 1 shows a high level flow chart of a method of carrying outembodiments of the disclosed technology. A specialized device, such as asearch engine database processing machine (such as a device as is shownin FIG. 4), is used in embodiments of the disclosed technology. Such adevice receives database queries and outputs results from the database.In step 110, the IDF for each n-gram in a plurality of strings, such asstrings within a database, dataset, or table within a database, isdetermined as is described above and described in the example shownbelow with respect to FIGS. 2 and 3. In step 120, the length of eachstring in the plurality of strings is determined, as described in theexample shown below with respect to FIGS. 2 and 3. In step 130, aninverted list for each n-gram is created, where the inverted list for agiven n-gram is composed of all strings that contain that n-gram. A listmay also contain unique identifiers of strings, instead of the actualstrings, for space efficiency (e.g., identifiers can be assigned by wayof mapping strings to their actual location in a database file). In step140, each inverted list is sorted by the length of the strings in thelist.

In step 150, a modification, which may be an insertion, a deletion, or acombination thereof, is received for a string within the plurality ofstrings. While the effects of doing so are discussed in greater detailwith respect to FIG. 3, in short, changes to even a single string in theplurality of strings causes a cascading effect of changes that need tobe determined. First, the IDF of one or more n-grams determined in step110 may change as n-grams are added and deleted. Second, the length ofthe strings determined in step 120 may change. Third, the inverted listsdetermined in step 130 may change. Fourth, a change in string lengths,due to the changes in n-gram IDFs, might necessitate re-sorting certaininverted lists. Fully propagating such updates is cost prohibitive, andtherefore, in the prior art, updates are performed on a weekly or lessoften basis while error gradually increases within the inverted lists.

Thus, in step 160, the IDFs of affected n-grams are recalculated. Instep 170, it is determined if a predefined error threshold has been met.The error threshold is determined with respect to the IDF of eachn-gram, and hence the frequency of the n-gram in the plurality ofstrings. Whenever updates occur, they result in a modification of then-gram's frequency, and hence its IDF. The error threshold specifies theerror we are willing to tolerate between the IDFs that have been used tocalculate the lengths of the strings as they currently appear in theinverted lists and the correct IDFs if the string updates were takeninto account. The error threshold is more tolerant for n-grams with lowIDF (very frequent n-grams) and less tolerant for n-grams with high IDFs(infrequent n-grams). The allowed errors in n-gram IDFs result inoutdated string lengths in the n-gram inverted lists. Hence, queryanswers, using stale string lengths may return both false negative andfalse positive results. In embodiments of the invention, errorthresholds are computed such that no false negatives ever occur and asmall number of false positives is allowed (such that incrementallyupdating the inverted lists becomes cost efficient).

Thus, in step 170, if a predefined error threshold is met, we proceed tosteps 180 and 190, and compute the correct lengths of affected stringsand resort the appropriate inverted lists.

Before delving into the specifics of the disclosed technology, in orderto understand the art, consider a collection of strings D, where everystring consists of a number of elements from universe U. For example,let string s={t_(l) , . . . , t_(n)}, t_(i)

U. Let df(t_(i)) be the total number of strings in D containing tokent_(i), and N be the total number of strings. Then:idf(t _(i))=log₂(1+N/df(t _(i)))

Another popular definition of IDF is based on the Okapi BM25 formula:

${{idf}\left( t_{i} \right)} = {\log_{2}\frac{N - {{df}\left( t_{i} \right)} + 0.5}{{{df}\left( t_{i} \right)} + 0.5}}$

The L₂ length (as described in the background of the disclosedtechnology and known in the prior art) of string s is computed as

${L_{2}(s)} = \sqrt{\sum\limits_{t_{i} \in s}{{idf}\left( t_{i} \right)}^{2}}$and one can also compute simpler lengths based on an L₁ distance. Definethe L₂ normalized TF/IDF, BM25 similarity of strings s₁ and s₂ as:

${S_{2}\left( {s_{1},s_{2}} \right)} = {\sum\limits_{t_{i} \in {s_{1}\bigcap s_{2}}}\frac{{{idf}\left( t_{i} \right)}^{2}}{{L_{2}\left( s_{1} \right)}{L_{2}\left( s_{2} \right)}}}$assuming that for short strings the term frequency of the majority oftokens is equal to 1. L₂ normalization forces similarity scores in therange [0, 1]. Furthermore, an exact match to the query always hassimilarity equal to 1 (it is the best match).

FIG. 2 shows an example of inverted lists corresponding to data stringsfrom a table of a database in embodiments of the invention. An invertedlist is a list of every string that contains a specific n-gram as asubstring. Strings are associated with unique identifiers 210 in theindex (e.g., identifier 1 might correspond to string “Nick Koudas” inthe database, while token t₁ might correspond to the 3-gram “Kou”). Eachstring is also associated with a partial weight which is equal tow(s,t _(i))=idf(t _(i))/L ₂(s)Thus, for example, string 1 in list t_(i) is valued at 0.7 using theequation above. By directly scanning the inverted lists corresponding totokens t₁, t₂, t₃, and so on, in one pass, all the strings that exceed adesignated similarity can be determined and reported. Irrelevant strings(i.e., strings whose intersection with the query is empty) are neveraccessed.

FIG. 3 shows a sample dataset from a database which may be used to carryout embodiments of the invention. In the following analyses and examplesthe strings in dataset 310 are decomposed into 3-grams. For example,string 12, “Nick Koudas”, is decomposed into 3-grams 320 which are‘##n’, ‘#ni’, ‘nic’, ‘ick’, ‘ck’, ‘k k’, ‘ko’, ‘kou’, ‘oud’, ‘uda’,‘das’, ‘as#’, ‘s##’. The symbol “#” represents the lack of any characterin that space (thus, the string ‘##n’ represents that ‘n’ is the firstcharacter in the string, represents that ‘ni’ are the first twocharacters in the string, and the reverse is true for the endingn-grams). The dataset 310 shown in FIG. 2 comprises 177 such distinct3-grams. Only 14 of the 3-grams appear in more than one string. The mostfrequent 3-gram is ‘s##’, with five appearances.

In embodiments of the invention, Consider now that we build the invertedlists corresponding to the 177 3-grams, and that insertions, deletionsand modifications arrive at regular time intervals. A single insertionor deletion of a string, changes the total number of strings N in thetable, and hence theoretically the weight associated with every single3-gram, according to the equations listed above. Complete propagation ofthe update would require recomputation of the length of each string. Forexample, a modification of a single string, changing “Nick Koudas” to“Nick Arkoudas” would have many consequences. First, this additionchanges the length of string 12 (a deletion would also change the lengthof the string). Second, the addition of 3-grams ‘k a’, ar', ‘ark’ and‘rko’. Third, the disappearance of 3-grams ‘k k’, and ‘Ko’. Aconsequence of almost any addition or deletion is that the partialweight of the string has to be updated in all inverted listscorresponding to the prior 3-grams which comprise the modified string.

Finally, consider the modification “Nick Koudas” to “Nick Kouda”,deleting 3-grams ‘das’, ‘as#’, and ‘s##’. The by-product of deleting oneoccurrence of 3-gram ‘s##’, and hence changing the IDF of this 3-gram,is that the lengths of all 5 strings containing this 3-gram change. Thisin turn means that the 72 lists corresponding to the 3-grams containedin all five strings need to be updated, since they contain partialweights computed using the old length of these strings. Propagating anupdate that changes the IDF of a very frequent 3-gram, necessitatesupdating a large fraction of the inverted lists.

An insertion can have one or more of the following consequences: 1. Itcan generate new tokens, and thus the creation of new inverted lists. 2.It might require adding new strings in existing inverted lists, henceaffecting the IDFs of existing tokens. 3. Most importantly, after aninsertion the total number of strings N increases by one. As a resultthe IDF of every single token gets slightly affected, which affects thelength of every string and hence all partial weights in the invertedlists. 4. String entries in inverted lists that have no connection tothe directly updated tokens might need to be updated. This happens whenthe length of a string changes due to an updated token, triggering anupdate to all other lists corresponding to the rest of the tokenscontained in that string. 5. The order of strings in a particularinverted list can change. This happens when a different number of tokensbetween two strings gets updated (e.g., 3 tokens in one string and 1token only in another), hence affecting the length of one string morethan the length of the other. Notice also that identifying the listscontaining a particular string whose partial weight needs to be updatedis an expensive operation. To accomplish this we need to retrieve theactual string and find the tokens it is composed of. There are twoalternatives for retrieving the strings. First, we can store the exactstring along with every partial weight in all lists. This solution ofcourse will duplicate each string as many times as the number of tokensit is composed of. The second option is to store unique stringidentifiers in the lists, and perform random accesses to the database toretrieve the strings. This solution will be very expensive if the totalnumber of strings contained in a modified list is large.

A deletion has the opposite effects of an insertion. A token mightdisappear if the last string containing the token gets deleted. Variousentries might have to be deleted from a number of inverted lists, thuschanging the IDFs of existing tokens. The number of strings N willdecrease by one. Thus, the IDF of all tokens, and hence, the lengths andpartial weights of all strings will slightly change, causing a cascadingeffect similar to the one described for insertions.

A modification does not change the total number of strings N, and hencedoes not affect the IDF of tokens not contained in the strings beingupdated. Nevertheless due to a modification, new tokens can be createdand old tokens can disappear. In addition, a modification can change theIDF of existing tokens, with similar cascading effects.

Fully propagating updates is infeasible for large datasets if updatesarrive regularly. The alternative is to determine an appropriate errorthreshold to limit the cascading effect of a given modification,including an insertion or deletion of characters or strings in thedataset. However, it is desirable to ensure that while full updates tothe inverted indexes are not taking place, the answers to queries areaccurate within a tolerance level. The tolerance level may be such thatno false positives or false dismissals of answers appear in answers toqueries.

The first way in which the updates may be limited is by relaxingrecalculations of N, the total number of strings in a dataset such as ina database. The change of N due to the modification of the total numberof strings causes a change in all n-gram IDFs. Let N_(b) be the totalnumber of strings when the inverted index was built. Then, N_(b) wasused for computing the IDFs of all n-grams. The IDFs will only beupdated if the current value of N diverges significantly from N_(b).Given a query q the loss of precision in evaluating the relaxedsimilarity S_(2,b)(q, s) is computed using N_(b) instead of N. Given thelog factor in the equations used above, by not updating N when it iswithin a threshold, the answer to queries will remain within anacceptable tolerance level as will be shown below. Still further, withroughly balanced insertions and deletions, the value of N vs N_(b)should not change very much in many practical applications.

When a specific n-gram changes, in embodiments of the disclosedtechnology, an update may be avoided if the computed error is below athreshold. A specific n-gram may change due to an insertion, deletion,or modification of a string in a dataset or database. Remember that asingle n-gram IDF modification can have a dire cascading effect on alarge number of inverted lists, as discussed above. Assume that the IDFof n-gram t_(i) has been computed using the document frequency at thetime the inverted index was built. In embodiments of the disclosedtechnology, the current document frequency df(t_(i)) may vary withinsome predefined threshold, the calculations of which will be explainedbelow. Again, the effect of a small number of updates to a particularn-gram is insignificant due to the log factor in calculating IDFs. Inaddition, the cost of propagating changes of frequently updated n-gramsis amortized. An important practical consideration here is that the mostsevere cascading effects during updates are caused by the most frequentn-grams, i.e., the n-grams with large document frequency df(t_(i)), andhence low inverse document frequency idf(t_(i)). The most frequentn-grams are obviously the ones that have highly populated invertedlists, and hence the ones causing the biggest changes to the invertedindex during updates. These are also the n-grams that are expected to beupdated more frequently in many practical applications of the disclosedtechnology, and thus, the predefined error threshold may differ based onassigning larger error thresholds to the frequent n-grams than the lessfrequent n-grams. It also follows that the low IDF n-grams (frequentn-grams) contribute the least in similarity scores S₂(q, s), due to thesmall partial weights associated with them. By delaying the propagationof updates to low IDF n-grams, the cost of updates is significantlyreduced, and at the same time, the loss of precision is limited.

Thus, it has been shown that delayed propagation of updates usingrelaxation in the number of strings N and document frequencies df(t_(i)) will improve update performance substantially, while at the sametime limit the loss of query precision. Next, we determine the exactloss in precision. Let N_(b) df_(b) (t), idf_(b) (t_(i)) be the totalnumber of strings, the document frequencies, and the inverse documentfrequencies of n-grams in U at the time the inverted index is built. LetN, df(t_(i)) and idf(t_(i)) be the current, exact values of the samequantities, after taking into account all updates to the dataset sincethe inverted index was built. Given a fully updated inverted index and aquery q, let the exact similarity score between q and any s □D be S₂ (q,s). Assuming now delayed update propagation, let the approximatesimilarity score computed using quantities *_(b) be S^(˜) ₂ (q, s). Therelation between S₂ and S^(˜) ₂ can now be quantified to determine theloss in precision as will be shown below.

To introduce notation with an easier exposition we present a looseanalysis first. To simplify our analysis assume that the total possibledivergence in the IDF of t_(i), by considering the divergence in both Nand df (t_(i)), is given by:

$\frac{{idf}_{p}\left( t_{i} \right)}{\rho} \leq {{idf}\left( t_{i} \right)} \leq {\rho \cdot {{idf}_{p}\left( t_{i} \right)}}$for some value ρ. The loss of precision with respect to ρ will now becalculated. The analysis is independent of the particular form of priorequations (referring to the IDF and BM25 similarity measures) and willalso hold for all other alternatives of these two measures.

Consider query q and arbitrary string s □D. Their L₂ based IDFsimilarity is equal to:

${S_{2}\left( {q,s} \right)} = \frac{\sum\limits_{t_{i} \in {q\bigcap s}}{{idf}\left( t_{i} \right)}^{2}}{\sqrt{\sum\limits_{t_{i} \in s}{{idf}\left( t_{i} \right)}^{2}}\sqrt{\sum\limits_{t_{i} \in q}{{idf}\left( t_{i} \right)}^{2}}}$

Let x equal the numerator, the contribution of the n-grams common toboth q and s to the score. Let y=Σ_(ti Ls\(q∩s)) idf(t_(i))² be thecontribution of n-grams in s that do not appear in q, andz=Σ_(ti Lq\(q∩s)) idf(t_(i))² the contributions of n-grams in q that donot appear in s.

Define f(x, y, z) as

$S_{2} = {{f\left( {x,y,z} \right)} = \frac{x}{\sqrt{x + y}\sqrt{x + z}}}$

The following derivation is based on the fact that the above function ismonotone increasing in x, and monotone decreasing in y, z, for positivex, y, z. It is easy to see that the latter holds.

Consider the function g(x)=1/f(x)²·f(x) is monotone increasing if andonly if g(x) is monotone decreasing.

${g(x)} = {\frac{\left( {x + y} \right)\left( {x + z} \right)}{x^{2}} = {1 + \frac{y + z}{x} + {\frac{y\; z}{x^{2}}.}}}$

Since 1/x and 1/x² are monotone decreasing, g(x) is monotone decreasing,hence f(x) is monotone increasing. The proof for f (y), f (z) isstraightforward.

Given the definition of x, y, z and relaxation factor ρ, it holds that:x _(b)/ρ² ≦x _(c)≦ρ² ρx _(b)y _(b) /ρ≦y _(c) ≦ρ·y _(b)z _(b)/ρ² ≦z _(c)≦ρ² ·z _(b),

where x_(b), y_(b), z_(b) are with respect to IDFs computed at buildtime, and x_(c), y_(c), z_(c) are the current, exact values of the samequantities.

We are given an inverted index built using IDFs idf_(b) (t_(i)), and aquery q with threshold τ. We need to retrieve all strings s□D: S₂(q,s)≧τ. What if a threshold τ′<τs.t. retrieving all s□D: S^(˜) ₂(q, s)≧τ′guarantees no false dismissals? Notice that for any s, given the proofabove, the current score S₂(q, s) can be both larger or smaller thanS^(˜) ₂(q, s), depending on which ngrams in x, y, z have been affected.If □s: S^(˜) ₂(q, s)<S₂(q, s), we need to introduce threshold τ′<τ toavoid false dismissals. Hence:

${\tau \leq S_{2} \leq \frac{\rho^{2}x_{b}}{\sqrt{{x_{b}/\rho^{2}} + {y_{b}/\rho^{2}}}\sqrt{{x_{b}/\rho^{2}} + {z_{b}/\rho^{2}}}}} = {\left. {\rho^{4}S_{2}^{\sim}}\Rightarrow\tau^{\prime} \right. = {\tau/\rho^{4}}}$

While this bound is a tolerable threshold in embodiments of theinvention, some false positives will be introduced in an answer to aquery.

Consider now a more involved analysis that shows that given a relaxationfactor ρ the actual loss in precision is a much tighter function of ρ.We want to quantify the divergence of S^(˜) ₂ from S₂, constrained onthe inequalities shown above and S₂(q, s)≧τ, given some query q andsimilarity threshold τ. The query can be formulated as a constraintoptimization problem. Minimize f(x_(b), y_(b), z_(b)) constraint upon:f(x _(c) ,y _(c) ,z _(c))≧τx _(c)/ρ² ≦x _(b)≦ρ² ·x _(c)y _(c)/ρ² ≦y _(b)≦ρ² ·y _(c)z _(c)/ρ² ≦z _(b)≦ρ² ·z _(c),where inequalities have been re-written after solving for x_(b), y_(b),z_(b) instead of x_(c), y_(c), z_(c) (the exact same inequalitiesactually result in this case).

First we show that f(x, y, z) is minimized for y=z. Let v=(y−z)/2 andu=(y+z)/2·f(x, y, z) is minimized, when g(x, y, z)=f²(x, y, z) isminimized (for positive x, y, z):

${g\left( {x,y,z} \right)} = {\frac{x^{2}}{\left( {x + u} \right)^{2} - v^{2}}.}$

g(x, y, z) is minimized when the denominator is maximized, i.e., whenv²=0□y=z. Now, f(x_(b), y_(b), y_(b)) is further minimized when x_(b) isminimized and y_(b) (or z_(b)) is maximized, according to our aboveanalysis. Hence, f(x_(b), y_(b), z_(b)) is minimized at:

${f\left( {{x_{c}/\rho^{2}},{\rho^{2}y_{c}},{\rho^{2}y_{c}}} \right)} = {\frac{x_{c}}{x_{c} + {\rho^{4}y_{c}}}.}$

Consequently:

$\left. {{f\left( {x_{c},y_{c},z_{c}} \right)} \geq \tau}\Rightarrow{\frac{x_{c}}{x_{c} + y_{c}} \geq \tau}\Rightarrow{y_{c} \leq {x_{c}{\frac{1 - \tau}{\tau}.}}} \right.$

Substituting the above equation into the equation proceeding it:

${{f\left( {{x_{c}/\rho^{2}},{\rho^{2}y_{c}},{\rho^{2}y_{c}}} \right)} \geq \frac{x_{c}}{x_{c} + {x_{c}\rho^{4\frac{1 - \tau}{\tau}}}}} = \frac{\tau}{\tau + {\rho^{4}\left( {1 - \tau} \right)}}$${\tau^{\prime} = \frac{\tau}{\tau + {\rho^{4}\left( {1 - \tau} \right)}}},$

Thus, the final equation satisfies all constraints, guaranteeing nofalse dismissals and having only few false positives in expectation.

The analysis assumed for simplicity the worst case scenario, where alln-gram IDFs take either their smallest or largest possible value. Inpractice, of course, the extreme values might not have been reached forall n-grams. Notice that at query evaluation time we know the exactdeviation of every n-gram IDF from its correct value. Clearly, we cantake this information into account to limit false positives evenfurther.

To further limit false positives, we define the global maximum deviationσ≦ρamong all n-gram IDFs in U. Then, at query time we compute themaximum deviation λ≦ρamong all n-gram IDFs in q. In deriving a lowerbound for threshold τ, we use λ as a relaxation factor for x_(b), z_(b)(the n-grams in q∩s and q\(q∩s)), and σ for y_(b) (the n-grams ins\(q∩s)). This lower bound in practice will be tighter than our finalequation above.

The update propagation algorithm conceptually works as follows. We havean inverted index consisting of one inverted list per token in U, whereevery list is stored on secondary storage. List entries {s,w(s, t_(i))}are stored in decreasing order of partial weights w. To support updatepropagation we will need to perform incremental updates on the sortedlists. Hence, embodiments of this invention may store each list as aB-tree sorted on w. At index construction time we choose slack ρ. Assumethat we buffer arriving updates and propagate them in batch at regulartime intervals (e.g., every 5 minutes). Let the updates be given in arelational table consisting of: 1. The type of update (insertion,deletion, modification); 2. The new data in case of insertions; 3. Theold data in case of deletions; 4. Both the old and new data in case ofmodifications. We also build an IDF table consisting of: 1. A token; 2.The IDF of the token; 3. The current, exact frequency of the tokendf(t); 4. The frequency of the token at construction time df_(b)(t).Before applying the batch update to the index, we load the IDF table inmain memory. In practice, the total number of tokens |U| for mostdatasets is fairly small. Hence, maintaining the IDF table in mainmemory is inexpensive.

Assuming that multiple token IDFs have changed, we need to scan theB-trees corresponding to these tokens, and retrieve all stringscontained therein (which requires at least one random I/O per string idfor retrieving the actual strings from the database). Then, we computethe new lengths of the strings, given the updated token IDFs. Finally,first we rebuild the B-trees corresponding to tokens whose IDF haschanged, and also update all other B-trees that contain those strings.Every time we process a string we store the string id in a hash tableand make sure that we do not process that string again, if it issubsequently encountered in another B-tree (this will be the case forstrings that contain multiple tokens whose IDFs have changed)

FIG. 4 shows a high-level block diagram of a computer that may be usedto carry out the invention. Computer 400 contains a processor 404 thatcontrols the overall operation of the computer by executing computerprogram instructions which define such operation. The computer programinstructions may be stored in a storage device 408 (e.g., magnetic disk,database) and loaded into memory 412 when execution of the computerprogram instructions is desired. Thus, the computer operation will bedefined by computer program instructions stored in memory 412 and/orstorage 408, and the computer will be controlled by processor 404executing the computer program instructions. Computer 400 also includesone or a plurality of input network interfaces for communicating withother devices via a network (e.g., the Internet). Computer 400 alsoincludes one or more output network interfaces 416 for communicatingwith other devices. Computer 400 also includes input/output 424,representing devices which allow for user interaction with the computer400 (e.g., display, keyboard, mouse, speakers, buttons, etc.). Oneskilled in the art will recognize that an implementation of an actualcomputer will contain other components as well, and that FIG. 4 is ahigh level representation of some of the components of such a computerfor illustrative purposes. It should also be understood by one skilledin the art that the method, devices, and examples depicted in FIGS. 1through 3 may be implemented on a device such as is shown in FIG. 4.

The foregoing Detailed Description is to be understood as being in everyrespect illustrative and exemplary, but not restrictive, and the scopeof the technology disclosed herein is not to be determined from theDetailed Description, but rather from the claims as interpretedaccording to the full breadth permitted by the patent laws. It is to beunderstood that the embodiments shown and described herein are onlyillustrative of the principles of the present technology and thatvarious modifications may be implemented by those skilled in the artwithout departing from the scope and spirit of the technology. Thoseskilled in the art could implement various other feature combinationswithout departing from the scope and spirit of the disclosed technology.

1. A method for limiting updates of inverted indexes in a database, themethod comprising: calculating a first inverse document frequency foreach n-gram in a plurality of strings; calculating a first inversedocument frequency related length for each string in the plurality ofstrings; for each n-gram, creating an inverted list comprising thestrings containing the n-gram; sorting each inverted list by the firstinverse document frequency related length of the strings in the invertedlist; receiving an update to the plurality of strings; determining whichn-grams are affected by the update; calculating, based on the update, asecond inverse document frequency of the affected n-grams; determiningwhich strings are affected by the update; calculating, based on theupdate, a second inverse document frequency related length of theaffected strings; determining which inverted lists are affected by theupdate; and for each affected inverted list: calculating an error basedon the second inverse document frequencies; determining whether theerror is less than a predefined error threshold; and upon determiningthat the error is not less than the predefined error threshold, updatingthe affected inverted list; and answering a query based on the updatedaffected inverted lists.
 2. The method of claim 1, wherein the update isan addition of a string.
 3. The method of claim 1, wherein the update isa deletion of a string.
 4. The method of claim 1, wherein the update isa modification of a string.
 5. The method of claim 1, wherein the erroris based on a difference between the second inverse document frequencyand the first inverse document frequency.
 6. The method of claim 1,wherein the predefined error threshold is determined such that no falsedismissals of an answer occur in answering the query.
 7. The method ofclaim 1, wherein the predefined error threshold is determined such thata small number of false positive answers is introduced in answering thequery.
 8. A search engine database processing device comprising: meansfor calculating a first inverse document frequency for each n-gram in aplurality of strings; means for calculating a first inverse documentfrequency related length for each string in the plurality of strings;means for, for each n-gram, creating an inverted list comprising thestrings containing the n-gram; means for sorting each inverted list bythe first inverse document frequency related length of the strings inthe inverted list; means for receiving an update to the plurality ofstrings; means for determining which n-grams are affected by the update;means for calculating, based on the update, a second inverse documentfrequency of the affected n-grams; means for determining which stringsare affected by the update; means for, for each affected inverted list:calculating an error based on the second inverse document frequencies;determining whether the error is less than a predefined error threshold;and upon determining that the error is not less than the predefinederror threshold, updating the affected inverted list; and means foranswering a query based on the updated affected inverted lists.
 9. Thedevice of claim 8, wherein the update is an addition of a string. 10.The device of claim 8, wherein the update is a deletion of a string. 11.The device of claim 8, wherein the update is a modification of a string.12. The device of claim 8, wherein the error is based on a differencebetween the second inverse document frequency and the first inversedocument frequency.
 13. The device of claim 8, wherein the predefinederror threshold is determined such that no false dismissals of an answeroccur answering the query.
 14. The device of claim 8, wherein thepredefined error threshold is determined such that a small number offalse positive answers is introduced in answering the query.